# coding=utf-8

from app.result.api.user import *
from app.dao.api.user import *


def login_service(email: str, password: str, token: str):
    try:
        # if login_check_in_other(token):
        #     return login_result(LoginCode.IN_OTHER)
        # if login_check_wait():
        #     return login_result(LoginCode.WAIT)
        if email == "":
            return login_result(LoginCode.NOT_MATCH)
        if password == "":
            return login_result(LoginCode.NOT_MATCH)
        user_model, user_json = login_dao(token, email, password)
        if not user_model:
            return login_result(LoginCode.NOT_MATCH)
        token = user_json["token"]
        if login_check_in_other(token):
            return login_result(LoginCode.IN_OTHER)
        if login_check_wait():
            return login_result(LoginCode.WAIT)
        if user_model.banned == 1:
            return login_result(LoginCode.IS_BAN)
        if user_model.is_delete == 1:
            return login_result(LoginCode.IS_DELETE)
        if not login_cache(user_model):
            return login_result(LoginCode.ERROR)
        return login_result(LoginCode.SUCCESS, user_json)

    except Exception as e:
        print(e)
        return login_result(LoginCode.ERROR)


def all_info_service(token: str):
    try:
        data = all_info(token)
        if not data:
            return all_info_result(AllInfoCode.ERROR)
        return all_info_result(AllInfoCode.SUCCESS, data)
    except Exception as e:
        print(e)
        return all_info_result(AllInfoCode.ERROR)
